package com.jml.jdk8.函数方法;

import java.util.Comparator;
import java.util.function.BinaryOperator;

/**
 * @Author: J
 * @DATE: 2022-04-15 14:35
 */
public class BinaryOperatorTest {
    public static void main(String[] args) {
        Comparator<String> comparator = (a, b) -> a.length() - b.length();
        BinaryOperatorTest binaryOperatorTest = new BinaryOperatorTest();
        String aShort = binaryOperatorTest.getShort("1234", "123", comparator);
        System.out.println(aShort);

        String aLong = binaryOperatorTest.getLong("1234", "123", comparator);
        System.out.println(aLong);
    }

    public String getShort(String a, String b, Comparator<String> comparator) {
        return BinaryOperator.minBy(comparator).apply(a, b);
    }

    public String getLong(String a, String b, Comparator<String> comparator) {
        return BinaryOperator.maxBy(comparator).apply(a, b);
    }
}
